
package com.studiofortress.sf.graphics.display;

import java.awt.event.KeyEvent;

/**
 * This event represents both key presses and key releases. It does not
 * represent a key being continually pressed (i.e. it'll only be sent once when
 * the key state changes between up and down).
 *
 * Use the isPressed() method to tell if the key was pressed or released.
 * 
 * @author Joseph Lenton - JosephLenton@StudioFortress.com
 */
public class ControlKeyEvent extends ControlEvent
{
    private final int keyCode;
    private final boolean pressed;

    /**
     * Creates a new key pressed or released event.
     * @param keyCode The standard key code for the key that was affected.
     * @param pressed True if the key is being pressed, false if released.
     */
    ControlKeyEvent(int keyCode, boolean pressed)
    {
        this.keyCode = keyCode;
        this.pressed = pressed;
    }

    /**
     * This returns true or false stating if this event represents a key down
     * or up.
     * @return True if this key was pressed, otherwise false if it is a release.
     */
    public boolean isPressed()
    {
        return pressed;
    }

    /**
     * This returns the code stored by the java.awt.event.KeyEvent class.
     * @return The code for the key that was pressed or released.
     */
    public int getKeyCode()
    {
        return keyCode;
    }
    
    /**
     * This name is the standard name used by the java.awt.event.KeyEvent class.
     * @return A string representation of the key that was pressed or released.
     */
    public String getKeyName()
    {
        return KeyEvent.getKeyText( keyCode );
    }
}
